/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tencent.tendon.convert.jsontest.refer;

import com.tencent.tendon.convert.json.JsonConvert;
import com.tencent.tendon.convert.jsontest.Utility;
import java.util.Arrays;
import java.util.List;

/**
 *
 * @author nbzhang
 */
public class Student {

    private String chname;

    private List<Student> friends;

    public Student() {
    }

    public Student(String name) {
        this.chname = name;
    }

    public static void main(String[] args) throws Throwable {
        Student st1 = new Student("张三");
        Student st2 = new Student("李四");
        Student st3 = new Student("王五");
        List<Student> friends = Arrays.asList(new Student[]{st1, st2, st3});
        st1.setFriends(friends);
        st2.setFriends(friends);
        st3.setFriends(friends);
        final String json = st1.toString();
        System.out.println(st1.toString());
        System.out.println(JsonConvert.convertTo(st1));
        Student newst1 = (JsonConvert.convertFrom(json, st1.getClass()));
        System.out.println(newst1);
        System.out.println(newst1.friends == newst1.friends.get(0).friends);
        System.out.println(newst1.friends == newst1.friends.get(1).friends);
        System.out.println(newst1.friends == newst1.friends.get(2).friends);
    }

    @Override
    public String toString() {
        return Utility.listingString(this);
    }

    public List<Student> getFriends() {
        return friends;
    }

    public void setFriends(List<Student> friends) {
        this.friends = friends;
    }

    public String getChname() {
        return chname;
    }

    public void setChname(String chname) {
        this.chname = chname;
    }
}
